import { ImageryProviderEnum } from '@/enums/LayerEnum';

interface parameters {
    format: string;
    transparent: boolean;
    crs: string;
}
interface providerOptions {
    // 定义 options 的结构
    url?: string;
    mapStyle?: string;
    key?: string;
    rectangle?: any;
    channel?: number;
    mapId?: string;
    fileExtension?: string;
    maximumLevel?: number;
    credit?: string;
    layers?: string;
    parameters?: parameters;
}

/**
 * 图层切换
 * ArcGisMapServerImageryProvider
 * SingleTileImageryProvider
 * BingMapsImageryProvider
 * GoogleEarthEnterpriseMapsProvider
 * MapboxImageryProvider
 * createOpenStreetMapImageryProvider
 * WebMapTileServiceImageryProvider
 * WebMapServiceImageryProvider
 */
export const providerChange = (viewer, type: ImageryProviderEnum, provider: providerOptions) => {
    // let provider = new Cesium.BingMapsImageryProvider();
    const layer = viewer.imageryLayers;
    if (layer.length > 0) {
        // 先移除移除影像图层
        layer.remove(layer.length - 1);
    }
    // 添加影像图层
    viewer.imageryLayers.addImageryProvider(provider);
};

export const providerAdd = (viewer, provider: any) => {
    // let provider = new Cesium.BingMapsImageryProvider();
    const layer = viewer.imageryLayers;
    if (layer.length > 0) {
        // 先移除移除影像图层
        layer.remove(layer.length - 1);
    }
    // 添加影像图层
    viewer.imageryLayers.addImageryProvider(provider);
};

export const providerDelete = (viewer) => {
    // let provider = new Cesium.BingMapsImageryProvider();
    const layer = viewer.imageryLayers;
    // 删除影像图层
    layer.removeAll();
};

// if (type === ImageryProviderEnum.ArcGisMapServerImagery){
//     provider = new Cesium.BingMapsImageryProvider({
//       url: 'https://dev.virtualearth.net',
//       mapStyle: Cesium.BingMapsStyle.AERIAL,
//       key: 'AraGkBfghounWbX8rAcEEL8VXISh5M7tbxnlGxKocM134GmIr-yr48WBJvfaRaCg' //当场景出现黑球时可至官网（https://www.bingmapsportal.com/）申请key
//     })
//   }else if (type === ImageryProviderEnum.SingleTileImagery){
//     provider = new Cesium.SingleTileImageryProvider({
//       url: 'https://www.google.cn/maps/@39.915,116.391,11z',
//       rectangle: Cesium.Rectangle.fromDegrees(114.14, 30.54, 114.54, 30.94)
//     })
//   }else if (type === ImageryProviderEnum.BingMapsImagery){
//     provider = new Cesium.BingMapsImageryProvider({
//       url: 'https://dev.virtualearth.net',
//       mapStyle: Cesium.BingMapsStyle.AERIAL,
//       key: 'AraGkBfghounWbX8rAcEEL8VXISh5M7tbxnlGxKocM134GmIr-yr48WBJvfaRaCg' //当场景出现黑球时可至官网（https://www.bingmapsportal.com/）申请key
//     })
//   }else if (type === ImageryProviderEnum.GoogleEarthEnterpriseMaps){
//     provider = new Cesium.GoogleEarthEnterpriseMapsProvider({
//       url: 'https://earthenterprise.google.com/earth/v1/imagery',
//       channel: 1,
//     })
//   }else if (type === ImageryProviderEnum.MapboxImagery){
//     provider = new Cesium.MapboxImageryProvider({
//       mapId: 'mapbox.satellite'
//     })
//   }else if (type === ImageryProviderEnum.createOpenStreetMapImagery){
//     provider = Cesium.createOpenStreetMapImageryProvider()
//   }else if (type === ImageryProviderEnum.WebMapTileServiceImagery){
//     provider = new Cesium.WebMapTileServiceImageryProvider({
//       url: 'http://www.google.cn/maps/vt?lyrs=s@189&gl=cn&x={x}&y={y}&z={z}',
//       fileExtension: 'jpg',
//       maximumLevel: 18,
//       credit: 'Google'
//     })
//   }else if (type === ImageryProviderEnum.WebMapServiceImagery){
//     provider = new Cesium.WebMapServiceImageryProvider({
//       url: 'http://www.google.cn/maps/kml?layers=0',
//       layers: '0',
//       parameters: {
//         format: 'image/jpeg',
//         transparent: true,
//         crs: 'EPSG:3857'
//       },
//       proxy: new Cesium.DefaultProxy('/proxy/')
//     })
//   }
